package com.example.mybatisplus.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.Bed;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatisplus.model.dto.BedInfoDTO;
import com.example.mybatisplus.model.dto.UnderDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lxp
 * @since 2024-07-17
 */
@Mapper
public interface BedMapper extends BaseMapper<Bed> {
    @Select("SELECT COUNT(*) FROM bed WHERE Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND bedtype='underg'AND isEnabled=1)")
    int getUndergBed(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT COUNT(*) FROM bed WHERE Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND bedtype='teacher'AND isEnabled=1)")
    int getTeacherBed(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT COUNT(*) FROM bed WHERE Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND bedtype='master'AND isEnabled=1)")
    int getMasterBed(@Param("areaname") String areaname, @Param("campusname") String campusname);
    @Select("SELECT COUNT(*) FROM bed WHERE Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND bedtype='doctoral'AND isEnabled=1)")
    int getDoctorBed(@Param("areaname") String areaname, @Param("campusname") String campusname);
    //房源分配
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='underg'AND isEnabled=1")
    int getUndergCount();
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='teacher'AND isEnabled=1")
    int getTeacherCount();
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='master'AND isEnabled=1")
    int getMasterCount();
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='doctoral'AND isEnabled=1")
    int getDoctorCount();

    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='underg'AND isEnabled=0")
    int getFreeUndergCount();
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='teacher'AND isEnabled=0")
    int getFreeTeacherCount();
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='master'AND isEnabled=0")
    int getFreeMasterCount();
    @Select("SELECT COUNT(*) FROM bed WHERE bedtype='doctoral'AND isEnabled=0")
    int getFreeDoctorCount();
    @Select("SELECT COUNT(*) FROM bed WHERE Room_Building_Area_areaId = (SELECT areaId FROM area WHERE areaName = #{areaname} AND campusName = #{campusname} AND isEnabled=0)")
    int getRestBed(@Param("areaname") String areaname, @Param("campusname") String campusname);
    Page<BedInfoDTO> findDisabledBed(@Param("page")Page<BedInfoDTO> page, @Param("areaName") String areaName, @Param("buildingName") String buildingName, @Param("floor") String floor);
    Page<UnderDTO> findUnderBed(@Param("page")Page<UnderDTO> page, @Param("areaName") String areaName, @Param("buildingName") String buildingName, @Param("floor") String floor);
    Page<UnderDTO> findPostBed(@Param("page")Page<UnderDTO> page,@Param("areaName") String areaName,@Param("buildingName") String buildingName,@Param("floor") String floor);
    //    List<UnderDTO> findPostBed();
    Page<UnderDTO> findStaffBed(@Param("page")Page<UnderDTO> page,@Param("areaName") String areaName,@Param("buildingName") String buildingName,@Param("floor") String floor);
    void updateBedTypeAndStatus(@Param("bedIds") List<Integer> bedIds, @Param("bedtype") String bedtype, @Param("isEnabled") int isEnabled);

}


